package com.CMS.client.ui.widgets;

import com.CMS.client.CMSConstants;
import com.CMS.client.NameTokens;
import com.CMS.client.UrlManagement;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Cookies;
import com.google.gwt.user.client.Window;
import com.smartgwt.client.widgets.Img;
import com.smartgwt.client.widgets.Label;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.layout.VLayout;

public class Masthead extends HLayout {

  private static final int MASTHEAD_HEIGHT =119;
  
  private CMSConstants constants = GWT.create(CMSConstants.class);
    
  public Masthead() {
	super();
	
    // initialise the Masthead layout container
	this.addStyleName("cms-Masthead");	
    //this.setHeight(MASTHEAD_HEIGHT);
    
	// initialise the Logo image
    Img logo = new Img("imgLogo.jpg",304,111); 
    logo.addStyleName("cms-Masthead-Logo");	  
    
	// initialise the Name label	
	Label name = new Label();  
	name.addStyleName("cms-MastHead-Name");  
	//name.setContents("CMS"); 
    
    // initialise the West layout container
    HLayout westLayout = new HLayout();
    westLayout.setHeight(MASTHEAD_HEIGHT);	
    westLayout.setWidth("50%");
    westLayout.addMember(logo);
    westLayout.addMember(name);
    
    // initialise the Signed In User label
	Label signedInUser = new Label();  
	signedInUser.addStyleName("cms-MastHead-SignedInUser");  
	signedInUser.setContents(Cookies.getCookie(NameTokens.USSER_SESSION)); 
	signedInUser.setHeight(35);
	//logout
	Label logOut = new Label(constants.logoutsession());
	logOut.setStyleName("cms-MastHead-LogOutUser");
	logOut.setHeight(5);

    // initialise the East layout container
    VLayout eastLayout = new VLayout();  
    eastLayout.setHeight(MASTHEAD_HEIGHT);
    eastLayout.setWidth("5%");
  
    
    VLayout alias =new VLayout();
    alias.setHeight(35);
    alias.addMember(signedInUser);
    
    VLayout close =new VLayout();
    close.setHeight(5);
    close.addMember(logOut);
    
    eastLayout.addMember(alias);
    eastLayout.addMember(close);
    
    logOut.addClickHandler(new com.smartgwt.client.widgets.events.ClickHandler() {
		
		@Override
		public void onClick(com.smartgwt.client.widgets.events.ClickEvent event)
		{
         
               Cookies.removeCookie(NameTokens.DEFAULT_PAGE);
               Cookies.removeCookie(NameTokens.USSER_SESSION);
               Cookies.removeCookie(NameTokens.TOKEN);
               //Window.open(UrlManagement.URL, "_self","");
               Window.Location.replace(UrlManagement.URL);
			   
			
		}
	});
    
    // add the West and East layout containers to the Masthead layout container
	this.addMember(westLayout);  	
	this.addMember(eastLayout); 
  }	
}